<?php

declare(strict_types=1);

namespace Modules\Production\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Modules\Base\Models\Material;
use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $order_id
 * @property $fseq
 * @property $fentry_id
 * @property $cargo_code
 * @property $cargo_name
 * @property $material_id
 * @property $qty
 * @property $wms_code
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class DassemblyOrderProduct extends Model
{


    protected $table = 'dassembly_order_product';

    protected $fillable = [ 'id', 'order_id', 'fseq', 'fentry_id', 'cargo_code', 'cargo_name', 'material_id', 'qty', 'wms_code', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','order_id','fseq','fentry_id','cargo_code','cargo_name','material_id','qty','wms_code','created_at','updated_at'];

    /**
     * @var array
     */
    protected array $form = ['id','order_id','fseq','fentry_id','cargo_code','cargo_name','material_id','qty','wms_code','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'id' => '=',
        'order_id' => '=',
        'material_id' => '=',
        'wms_code' => '=',
    ];

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    /**
     * 关联产品信息
     * @return HasMany
     */
    public function material()
    {
        return $this->hasOne(Material::class,'id','material_id');
    }

    /**
     * 关联单据头
     * @return HasMany
     */
    public function order()
    {
        return $this->hasOne(DassemblyOrder::class,'id','order_id');
    }


}
